package com.ytjj.qmyx.data.amqp.consumer;

import com.rabbitmq.client.Channel;
import com.ytjj.common.constants.QueueConstants;
import com.ytjj.common.dto.mqdto.PageStatisticsDto;
import com.ytjj.qmyx.data.service.PageStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 *
 *  *
 **/
@Slf4j
@Component
public class PageStatisticsListener {

    @Resource
    private PageStatisticsService pageStatisticsService;

    @RabbitListener(queuesToDeclare = @Queue(value = QueueConstants.PAGE_STATISTICS_QUEUE, durable = "true"))
    public void pageStatistics(PageStatisticsDto pageStatisticsDto, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) {
        log.debug("页面统计消息：\n{}",pageStatisticsDto);
        try {
            pageStatisticsService.pageStatistics(pageStatisticsDto);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("页面统计消息失败：\n{}",pageStatisticsDto);
        }
    }
}
